import service from "./request";

export const httpGet = (uri, params) => service.get(uri, { params });
export const httpConfigGet = (uri, params, config) => service.get(uri, { ...config, params });

export const httpPost = (uri, data = {}, params) => service.post(uri, data, { params });
export const httpConfigPost = (uri, data = {}, config = {}) => service.post(uri, data, { ...config });

export const httpPut = (uri, data = {}, params) => service.put(uri, data, { params });
export const httpConfigPut = (uri, data = {}, config) => service.put(uri, data, { ...config });

export const httpDelete = (uri, params, data) => {
  if (params) {
    return service.delete(uri, { params });
  } else {
    return service.delete(uri, { data });
  }
};

export const httpConfigDelete = (uri, params, data, config) => {
  if (params) {
    return service.delete(uri, { ...config, params });
  } else {
    return service.delete(uri, { ...config, data });
  }
};

// blob
export const httpGetBlob = (uri, params) => service.get(uri, { params, responseType: "blob" });

// 文件上传
export const httpUploadPost = (uri, data) => {
  const headers = { "Content-Type": "multipart/form-data", Accept: "*/*" };
  return service.post(uri, data, { headers });
};
